/**
 * @author htqw
 */

import createTable from './create.js'
import dropTable from './drop.js'
import insertTableData from './insert.js'
import selectTableData from './select.js'
import deleteTableRow from './delete.js'
import updateTableCols from './update.js'

export default function tableOpertions(connection, checkType, checkColumns) {
    /**
     * 
     * @param {String} name 
     * @param {import('./create.js').Columns} columns 
     */
    function create(name, columns) {
        checkColumns(checkType, types, columns)
        return createTable(connection, name, columns)
    }

    /**
     * 
     * @param {string} name
     */
    function drop(name) {
        return dropTable(connection, name)
    }

    /**
     * 
     * @param {string} name 
     * @param {Object.<string, string>} data 
     * @returns 
     */
    function insert(name, data) {
        return insertTableData(connection, name, data)
    }

    /**
     * 
     * @param {string} name 
     * @param {Object.<string, string>} data 
     * @param {string | undefined} where 
     * @returns 
     */
    function update(name, data, where) {
        return updateTableCols(connection, name, data, where)
    }

    /**
     * 
     * @param {string} name 
     * @param {string[]} columns 
     * @param {string} where 
     * @returns 
     */
    function select(name, columns, where) {
        return selectTableData(connection, name, columns, where)
    }

    /**
     * 
     * @param {string} name 
     * @param {string} where 
     * @returns 
     */
    function del(name, where) {
        return deleteTableRow(connection, name, where)
    }

    return {
        create,
        drop,
        insert,
        select,
        del,
        update
    }
}